import bpy, os
import numpy as np
import pandas as pd
from math import radians
from tool.cam import Cam
from tool.cylinder import Cylinder
from remote_run_everything import Common
import pickle


class CreateScent:
    def __init__(self):
        self.cy = Cylinder()
        self.cam = Cam()
        self.root = "D://ai/my_blender"

    def run(self):
        full1 = False
        full2 = False
        for ep in range(3000):
            if ep > 1000: full1 = True
            if ep > 2000: full2 = True
            self.cy.clear()
            self.cy.get_data(1, full1)
            self.cy.get_data(2, full2)
            self.cy.get_data(3, False)
            self.cy.add_row()
            total = self.cy.count_data()
            nu = Common().prefix_zero(6, ep)
            path1 = f"{self.cy.d2}/{nu}l_{total}.png"
            self.cam.render(path1)
            path2 = f"{self.cy.d2}/{nu}r_{total}.png"
            self.cam.move_cam()
            self.cam.render(path2)
            self.cam.move_cam_back()

    def one(self):
        self.cy.clear()
        self.cy.get_data(1, True)
        self.cy.get_data(2, True)
        self.cy.get_data(3, True)
        locs = self.cy.add_row()
        path1 = f"{self.root}/cache/1.png"
        path2 = f"{self.root}/cache/2.png"

        self.cam.render(path1)
        uvs1 = [self.cam.wordloc2uv(loc) for loc in locs]

        self.cam.move_cam()
        self.cam.render(path2)
        uvs2 = [self.cam.wordloc2uv(loc) for loc in locs]
        self.cam.move_cam_back()
        d = {"loc": locs, "uv1": uvs1, "uv2": uvs2}
        with open(f"{self.root}/cache/loc.pickle", "wb") as f:
            pickle.dump(d, f)


if __name__ == '__main__':
    c = CreateScent()
    c.one()
